package com.lanyou.esb.service;

import java.util.Calendar;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lanyou.esb.redis.proxy.impl.ServiceTimeJedisProxy;

/**
 * CookProxy服务器时间服务
 * 
 * @author Davey.wu
 */
@Service
public class CookProxyServiceTimeService {
	@Autowired
	private ServiceTimeJedisProxy serviceTimeJedisProxy;

	/**
	 * 获取CookProxy服务器的时间
	 * 
	 * @return
	 */
	public Calendar getCookProxyServiceTime() {
		Long value = null;
		try {
			value = serviceTimeJedisProxy.get(serviceTimeJedisProxy
					.generateKey(""));
		} catch (Exception e) {
			return null;
		}
		if (value == null || value.longValue() <= 0) {
			return null;
		}
		Calendar calendar = null;
		try {
			calendar = Calendar.getInstance();
			calendar.setTimeInMillis(value.longValue());
		} catch (Exception e) {
			calendar = null;
		}
		return calendar;
	}
}
